#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <cstdlib>
#define LL long long
#define ldb long double
const ldb eps = 1e-9;
const ldb pi = fabsl(atan2(0.0, -1.0));
const int INF = 0x7f7f7f7f;
const LL LINF = 1ll << 60;
const ldb LDINF = 1e42;
#define nextLine() {int c = 0; while ((c = getchar()) != 10 && c != EOF);}
#define addEdge(a, b) next[edges] = first[a]; first[a] = edges; end[edges] = b; edges++;
using namespace std;

int n, m;
int a[22][22];
LL t[22][22];
LL h[4];
set <vector< vector<int> > > was;
const int X = 23;
const int Y = 17;

void Load()
{
	cin >> n >> m;
	int i, j;
	nextLine();
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			a[i][j] = getchar();
		}
		nextLine();
	}
}

vector <vector<int> > getSmall(int i, int j, int x, int y)
{
	int k, l;
	vector<vector<int> > t, t1, res;
	t.resize(x);
	for (k = 0; k < x; k++)
		t[k].resize(y);
	t1.resize(y);
	for (k = 0; k < y; k++) t1[k].resize(x);


	for (k = 0; k < x; k++)
	{
		for (l = 0; l < y; l++)
		{
			t[k][l] = a[i + k][j + l];
			t1[y - l - 1][k] = t[k][l];
		}
	}
	res = t;
	if (res > t1) res = t1;

	for (k = 0; k < y; k++)
	{
		for (l = 0; l < x; l++)
		{
			t[x - l - 1][k] = t1[k][l];
		}
	}
	if (res > t) res = t;
	for (k = 0; k < x; k++)
	{
		for (l = 0; l < y; l++)
		{
			t1[y - l - 1][k] = t[k][l];
		}
	}
	if (res > t1) res = t1;
	return res;
}

void Solve()
{
	int x, y;
	int res = INF, rx, ry;
	int all = 0;
	int i, j;
	bool ok;
	vector<vector<int> > sm;
	for (x = 1; x <= n; x++)
	{
		if (n % x != 0) continue;
		for (y = 1; y <= m; y++)
		{
			if (m % y != 0) continue;
			if (!was.empty()) was.erase(was.begin(), was.end());
			ok = true;
			for (i = 0; ok && i < n / x; i++)
			{
				for (j = 0; ok && j < m / y; j++)
				{
					sm = getSmall(i * x, j * y, x, y);
					if (was.find(sm) != was.end())
					{
						ok = false;
						break;
					}
					was.insert(sm);
				}
			}
			if (ok)
			{
				all++;
				if (res > x * y || res == x * y && x < rx)
				{
					res = x * y;
					rx = x;
					ry = y;
				}
			}
		}
	}
	cout << all << "\n" << rx << " " << ry;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}